package test.study.concurrent.thread._3_future.future_task;

import cn.hutool.core.thread.ThreadUtil;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.FutureTask;

/**
 * 这个 result 是设置好传进去的
 * FutureTask 只是在 Runnable 执行完之后返回预先设置好的 result，以便通知任务已完成
 */
@Slf4j
public class _1_FutureTask_Main {

    @SneakyThrows
    public static void main(String[] args) {
        //step-1: new FutureTask
        FutureTask task = new FutureTask(() -> {
            log.info(">>>>>> callable");
            ThreadUtil.sleep(3 * 1000);
            log.info(">>>>>> callable");
            return "aaaaaaaaaaaaaa";
        });

        //step-2: thread execute with FutureTask
        new Thread(task)
                .start();

        //step-3: get result with FutureTask
//        Object result = task.get();
//        log.info("{}", result);
    }
}
